from selenium.webdriver.common.by import By

from webapp1.po.base_page import BasePage


class RegisterPage(BasePage):
    _uesrname1 = By.ID, 'loginname'
    _pwd = By.CSS_SELECTOR, '#signup_form > div:nth-child(2) > div > input'
    _repwd = By.CSS_SELECTOR, '#signup_form > div:nth-child(3) > div > input'
    _email = By.CSS_SELECTOR, '#signup_form > div:nth-child(4) > div > input'
    _registerbtn = By.CSS_SELECTOR, 'input[class="span-primary"]'

    _error_tip_text = By.CSS_SELECTOR,'div.alert.alert-error>strong'
    _success_tip_text = By.CSS_SELECTOR, 'div.alert.alert-success>strong'

    def go_to_register_with_email(self, username, pwd, repwd, email):
        self._driver.find_element(*self._uesrname1).send_keys(username)
        self._driver.find_element(*self._pwd).send_keys(pwd)
        self._driver.find_element(*self._repwd).send_keys(repwd)
        self._driver.find_element(*self._email).send_keys(email)
        self._driver.find_element(*self._registerbtn).click()

    @property
    def get_error_tip_text(self):
        return self._driver.find_element(*self._error_tip_text).text

    @property
    def get_success_tip_text(self):
        return self._driver.find_element(*self._success_tip_text).text
